<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .list-wrap{
            overflow-y: auto;
            position: relative;
        }
        .list{
            position: absolute;
            top: 0;
        }
        .item {
            height: 30px;
        }
    </style>
</head>
<body>

    <div id="app">
        <div class="list-wrap" id="listWrap"  onscroll="scrollListener()">
            <div class="scroll-bar" id="scrollBar" >
                <ul class="list" id="list"> 
                    
                </ul>
            </div>
        </div>
    </div>
    <script src="https://unpkg.com/vue@next"></script>
    <script>
        var list = []
        var showList = []
        var itemHeight = 30
        var showNum = 10
        var start = 0
        var end = 10
       
        for(let i=0 ;i<1000000; i++){
            this.list.push("列表" + i)
        }

        
                //计算滚动容器高度
        document.getElementById("listWrap").style.height = itemHeight * showNum + 'px'
        document.getElementById("scrollBar").style.height = itemHeight * list.length + 'px'

        function scrollListener(){
            let scrollTop =  document.getElementById("listWrap").scrollTop
            start = Math.floor(scrollTop / itemHeight)
            end = start + showNum
            show()
            document.getElementById("list").style.top = start * itemHeight + 'px'
        }

        function show(){
            showList = list.slice(start, end)
            console.log(start, end)
            var  eles = ""
            for(var i=0; i<showList.length;i++){
                eles += "<li class='item'>" + showList[i] + "</li>"
            }
            document.getElementById("list").innerHTML = eles
        }
        show()
    </script>
    
</body>
</html>